package com.zeng.sys.filemd.servicemodule.vo;

import com.zeng.nicecore.convert.AbstractConvertor;
import com.zeng.nicecore.util.BeanUtil;
import com.zeng.nicecore.validation.ValidGroup;
import com.zeng.sys.filemd.servicemodule.entity.FileRecord;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Null;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class FileRecordVo {
    //文件名称
    private String name;
    //文件路径 
    private String path;
    //文件大小
    private String size;
    //文件类型标识
    private String fileTypeCode;
    //文件服务器标识
    private String fileServerCode;
    //文件类型
    private String type;
    //文件状态
    private String status;
    //上传人标识
    private String uploadUserCode;
    //文件上传人昵称
    private String nickName;

    private String multipartKey;

    private InputStream dataWithInputStream;

    private byte[] dataWithByte;

    private FileServerVo fileServerVo;

    private List<String> codes;

    @Null(groups = ValidGroup.add.class,message = "version must be empty when adding records ")
    private Integer version;

    @Null(groups = ValidGroup.add.class,message = "valid must be empty when adding records ")
    private Short valid;

    @Null(groups = ValidGroup.add.class,message = "code must be empty when adding records")
    @NotEmpty(groups = ValidGroup.update.class,message = "code must be excluded where update record ")
    private String code;

    @Null(groups = ValidGroup.add.class,message = "id must be empty when adding records")
    private Integer id;

    @Null(groups = ValidGroup.add.class,message = "updateDate must be empty when adding records")
    private Date updateDate;

    @Null(groups = ValidGroup.add.class,message = "insertDate must be empty when adding records")
    private Date insertDate;

    public FileRecord convertToFileRecord(){
        return new FileRecordVoConvertable().voToBean(this);
    }

    public static FileRecordVo convertToFileRecordVo(FileRecord fileRecord){
        return new FileRecordVoConvertable().beanToVo(fileRecord);
    }

    public static List<FileRecordVo> listFileRecordVo(List<FileRecord> fileRecords){
        return new FileRecordVoConvertable().toList(fileRecords);
    }

    public static List<FileRecord> listFileRecord(List<FileRecordVo> fileRecordVos){
        return new FileRecordVoConvertable().toBeanList(fileRecordVos);
    }

    private static class FileRecordVoConvertable implements AbstractConvertor<FileRecord, FileRecordVo> {

        @Override
        public FileRecordVo beanToVo(FileRecord fileRecord) {
            return BeanUtil.beanToVo(fileRecord, new FileRecordVo());
        }
    
        @Override
        public FileRecord voToBean(FileRecordVo fileRecordVo) {
            return BeanUtil.VoToBean(fileRecordVo, new FileRecord());
        }
    }
}